package com.gt.web.srv.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.gt.web.srv.domain.BaseAuto;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Objects;


@Component
public class Auto implements MetaObjectHandler {



   /**
    * 使用mp做添加操作时候，这个方法执行
    *
    * @param metaObject 元对象
    */
   @Override
   public void insertFill(MetaObject metaObject) {

       if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseAuto) {
           BaseAuto base = (BaseAuto) metaObject.getOriginalObject();
           LocalDateTime now = LocalDateTime.now();
           base.setCreateTime(now);
           base.setUpdateTime(now);
       }
   }

   /**
    * 使用mp做修改操作时候，这个方法执行
    *
    * @param metaObject 元对象
    */
   @Override
   public void updateFill(MetaObject metaObject) {
       if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseAuto) {
           BaseAuto base = (BaseAuto) metaObject.getOriginalObject();
           LocalDateTime now = LocalDateTime.now();
           base.setUpdateTime(now);
       }
   }

}